{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "21bbb094",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c6a54aa9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1获取数据集\n",
    "data = pd.read_csv(\"./FacebookData/train.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0f7b0e35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>row_id</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>time</th>\n",
       "      <th>place_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.7941</td>\n",
       "      <td>9.0809</td>\n",
       "      <td>54</td>\n",
       "      <td>470702</td>\n",
       "      <td>8523065625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>5.9567</td>\n",
       "      <td>4.7968</td>\n",
       "      <td>13</td>\n",
       "      <td>186555</td>\n",
       "      <td>1757726713</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>8.3078</td>\n",
       "      <td>7.0407</td>\n",
       "      <td>74</td>\n",
       "      <td>322648</td>\n",
       "      <td>1137537235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>7.3665</td>\n",
       "      <td>2.5165</td>\n",
       "      <td>65</td>\n",
       "      <td>704587</td>\n",
       "      <td>6567393236</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>4.0961</td>\n",
       "      <td>1.1307</td>\n",
       "      <td>31</td>\n",
       "      <td>472130</td>\n",
       "      <td>7440663949</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   row_id       x       y  accuracy    time    place_id\n",
       "0       0  0.7941  9.0809        54  470702  8523065625\n",
       "1       1  5.9567  4.7968        13  186555  1757726713\n",
       "2       2  8.3078  7.0407        74  322648  1137537235\n",
       "3       3  7.3665  2.5165        65  704587  6567393236\n",
       "4       4  4.0961  1.1307        31  472130  7440663949"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "cf7de1ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2 数据预处理\n",
    "# 1)时间处理\n",
    "time_column = pd.to_datetime(data[\"time\"],unit=\"s\")\n",
    "time_column\n",
    "data[\"new_time\"] = time_column\n",
    "data.head()\n",
    "# 2)过滤掉签到次数少的\n",
    "place_count = data.groupby(\"place_id\").count()[\"x\"]\n",
    "data_final = data[data[\"place_id\"].isin(place_count[place_count > 3].index.values)]\n",
    "\n",
    "data_final.head()\n",
    "# 3 数据集划分\n",
    "# 数据集太大 跑不动 \n",
    "data_final = data_final.query(\"x < 2.5 & x > 2 & y < 1.5 & y > 1.0\")\n",
    "data_final.head()\n",
    "\n",
    "x = data_final[[\"x\",\"y\",\"accuracy\",\"new_time\"]]\n",
    "y = data_final[\"place_id\"]\n",
    "\n",
    "from sklearn.model_selection import train_test_split\n",
    "x_train,x_test,y_train,y_test = train_test_split(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "857c2125",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>new_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>2.2360</td>\n",
       "      <td>1.3655</td>\n",
       "      <td>66</td>\n",
       "      <td>1970-01-08 05:06:14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>180</th>\n",
       "      <td>2.2003</td>\n",
       "      <td>1.2541</td>\n",
       "      <td>65</td>\n",
       "      <td>1970-01-08 01:29:55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>367</th>\n",
       "      <td>2.4108</td>\n",
       "      <td>1.3213</td>\n",
       "      <td>74</td>\n",
       "      <td>1970-01-07 17:01:07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>874</th>\n",
       "      <td>2.0822</td>\n",
       "      <td>1.1973</td>\n",
       "      <td>320</td>\n",
       "      <td>1970-01-02 15:52:46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1022</th>\n",
       "      <td>2.0160</td>\n",
       "      <td>1.1659</td>\n",
       "      <td>65</td>\n",
       "      <td>1970-01-03 09:46:33</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           x       y  accuracy            new_time\n",
       "112   2.2360  1.3655        66 1970-01-08 05:06:14\n",
       "180   2.2003  1.2541        65 1970-01-08 01:29:55\n",
       "367   2.4108  1.3213        74 1970-01-07 17:01:07\n",
       "874   2.0822  1.1973       320 1970-01-02 15:52:46\n",
       "1022  2.0160  1.1659        65 1970-01-03 09:46:33"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e3f67cee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "112     7663031065\n",
       "180     2358558474\n",
       "367     6644108708\n",
       "874     3229876087\n",
       "1022    3244363975\n",
       "Name: place_id, dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4a496950",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>row_id</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>time</th>\n",
       "      <th>place_id</th>\n",
       "      <th>new_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>112</td>\n",
       "      <td>2.2360</td>\n",
       "      <td>1.3655</td>\n",
       "      <td>66</td>\n",
       "      <td>623174</td>\n",
       "      <td>7663031065</td>\n",
       "      <td>1970-01-08 05:06:14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>180</th>\n",
       "      <td>180</td>\n",
       "      <td>2.2003</td>\n",
       "      <td>1.2541</td>\n",
       "      <td>65</td>\n",
       "      <td>610195</td>\n",
       "      <td>2358558474</td>\n",
       "      <td>1970-01-08 01:29:55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>367</th>\n",
       "      <td>367</td>\n",
       "      <td>2.4108</td>\n",
       "      <td>1.3213</td>\n",
       "      <td>74</td>\n",
       "      <td>579667</td>\n",
       "      <td>6644108708</td>\n",
       "      <td>1970-01-07 17:01:07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>874</th>\n",
       "      <td>874</td>\n",
       "      <td>2.0822</td>\n",
       "      <td>1.1973</td>\n",
       "      <td>320</td>\n",
       "      <td>143566</td>\n",
       "      <td>3229876087</td>\n",
       "      <td>1970-01-02 15:52:46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1022</th>\n",
       "      <td>1022</td>\n",
       "      <td>2.0160</td>\n",
       "      <td>1.1659</td>\n",
       "      <td>65</td>\n",
       "      <td>207993</td>\n",
       "      <td>3244363975</td>\n",
       "      <td>1970-01-03 09:46:33</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      row_id       x       y  accuracy    time    place_id            new_time\n",
       "112      112  2.2360  1.3655        66  623174  7663031065 1970-01-08 05:06:14\n",
       "180      180  2.2003  1.2541        65  610195  2358558474 1970-01-08 01:29:55\n",
       "367      367  2.4108  1.3213        74  579667  6644108708 1970-01-07 17:01:07\n",
       "874      874  2.0822  1.1973       320  143566  3229876087 1970-01-02 15:52:46\n",
       "1022    1022  2.0160  1.1659        65  207993  3244363975 1970-01-03 09:46:33"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_final.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c5e8a1d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4特征工程 "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
